{% extends "base.html" %}
{% block title %}借阅卡详情{% endblock %}
{% block content %}
<h2>欢迎{{current_user.username}}来到图书管理系统，您的角色为{{get_current_role()}}</h2>

{% if current_user.borrow_card_apply_status == BorrowCardApplyStatus.APPLIED.value %}
{% if borrow_card %}
<h3>您的借阅卡信息如下</h3>
 
    <ul>
        <li>借阅卡号: {{ borrow_card.card_id }}</li>
        <li>用户名: {{ current_user.username }}</li>
        <li>借阅上限: {{ borrow_card.borrow_limit }} - 您已借阅{{ borrow_book_count }}本书，还可以借阅{{ borrow_card.borrow_limit - borrow_book_count }}本书
            {% if borrow_card.borrow_limit > borrow_book_count %}
            <a href="{{ url_for('user_borrow.book_list') }}">去借书</a>
            {% endif %}
        </li>
        <li>有效期: {{ borrow_card.valid_until }}</li>
    </ul>

    {% if overdue_book_count > 0 %}
        <h3>您有{{ overdue_book_count }}本借阅已过期，请尽快还书。</h3>
    {% elif borrow_card.borrow_limit <= borrow_book_count %}
        <h3>当前借阅卡可以正常借阅书籍</h3>
    {% else %}
        <h3>您的借阅卡借阅上限已用完，请尽快还书或续借。</h3>
    {% endif %}
{% endif %}
{% elif current_user.borrow_card_apply_status == BorrowCardApplyStatus.APPLYING.value %}
<h3>您的借阅卡已提交申请，正在审核中，请稍等。</h3>
{% elif current_user.borrow_card_apply_status == BorrowCardApplyStatus.UNAPPLY.value %}
<form method="POST" action="{{ url_for('user_card.card_view') }}">
    {{ form.hidden_tag() }}
    <!-- <p>
        {{ form.age.label }}<br>
        {{ form.age(size=32) }}
        {% for error in form.age.errors %}
            <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p> -->
    <p>
        {{ form.gender.label }}<br>
        {{ form.gender(size=2) }}
        {% for error in form.gender.errors %}
            <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p>
    <p>
        {{ form.birthday.label }}<br>
        {{ form.birthday(size=32) }}
        {% for error in form.birthday.errors %}
            <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p>
    <p>
        {{ form.user_idcard.label }}<br>
        {{ form.user_idcard(size=32) }}
        {% for error in form.user_idcard.errors %}
            <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p>
    <p>
        {{ form.user_phone.label }}<br>
        {{ form.user_phone(size=32) }}
        {% for error in form.user_phone.errors %}
            <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p>
    <p>{{ form.submit() }}</p>
</form>
{% endif %}
<a href="{{ url_for('user_borrow.book_list') }}">返回书籍列表</a>
{% endblock %}
